<?php

/* 
 * EachGo电商网站 新媒体
 * www.eachgo.cn
 */
namespace Home\Controller;
use Think\Controller;
//use Home\Model;
//use Think\Model;
class ShippingAddressController extends Controller{
    public function deleteAddress(){
        $address=D("shippingAddress");
        $result=$address->deleteAddress($_GET[addressId]);
        $this->redirect('ShippingAddress/showAddress',array(),0,'');
    }
    public function showAddress(){
        $address=D("shippingAddress");
        $userInfo=session('UserInfo');
        //var_dump($userInfo['phonenumber']);
        if(!empty($_POST)){
            if($_POST['addressId']!=NULL){
                $result=$address->updateAddress($_POST);
            }else{
                $addAddress=array_merge($_POST,array('user_phoneNumber'=>$userInfo['phonenumber']));
                $result=$address->addAddress($addAddress);
            }
        }
//        if(empty($result)){
//            echo "跳转到错误页面";
//        }
        //var_dump($address);
        $AddressInfo=$address->queryAllAddress($userInfo['phonenumber']);
        //var_dump($AddressInfo);
        $this->assign('AddressInfo',$AddressInfo);
        $this->display('User/showAddress');
    }
     public function queryByUserId(){
        $address=D("shippingAddress");
        $result=$address->queryAddressByUserId(13459876234);
        var_dump($result);
    }
    public function setDefaultAddress(){//设置默认地址
        $address=D("shippingAddress");
        $userInfo=session('UserInfo');
        //获取当前用户电话和要设置未默认地址的地址id
        $result=$address->setDefault($userInfo['phonenumber'],$_GET['addressId']);
        $this->redirect('ShippingAddress/showAddress',array(),0,'');
    }

}
